<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>ES6的类</h1>
    <p>ES6可以使用class来表示一个类。</p>
    <p>class中，需要使用constructor来写明构造方法。</p>
    <p>class中，使用 函数名(){ } 方式来定义方法。</p>
    <script>
        class Point {

            point_name = "默认圆";

            constructor(x,y) {
                this.x = x;
                this.y = y;
            }

            distance(other) {
                let r = Math.pow(this.x - other.x,2) + Math.pow(this.y - other.y,2);
                return Math.pow(r,0.5);
            }

            setPointName(name) {
                this.point_name = name;
            }

            getPointName() {
                return this.point_name;
            }
        }

        let point1 = new Point(50,50);

        let point2 = new Point(100,100);

        // point1.setPointName("圆1");
        console.log(point1.getPointName());

        console.log(point1.distance(point2));

    </script>
</body>
</html>